package priv.lirenhe.javasuper.io.stream2;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferInOutputStream {
	
	public static void main(String[] args) {
		File sourceFile = new File("C:\\Users\\Administrator\\workspace\\huali\\navicat121_premium_cs_x64.exe");
		File destFile = new File("C:\\Users\\Administrator\\workspace\\huali\\jiwang\\navicat121_premium_cs_x64.exe");
	
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		
		try {
			bis = new BufferedInputStream(new FileInputStream(sourceFile));
			bos = new BufferedOutputStream(new FileOutputStream(destFile));
			
			Long startTime = System.currentTimeMillis();
			int b;
			int len = 0;
			while((b = bis.read()) != -1){
				bos.write(b);
				len++;
//				System.out.println(b);
				if(len == 1024*1024){
					System.out.print(".");
					len = 0;
				}
			}
			Long endTime = System.currentTimeMillis();
			System.out.println(endTime - startTime);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(bos != null){
				try {
					bos.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(bis != null){
				try {
					bis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
